package com.equipment;

import com.util.EncodingUtil;

/**
 * 发送更新信息指令 FDA7 版本1.17
 * @version 1.18
 * @author 刘亚东
 *
 */
public class UpdateInformationRequest {

	private String STX = "55AA"; // 帧开始标志
	private String RSCTL = "00"; // 串口帧序列号
	private String Length = ""; // 长度
	private String code = "FD"; // 代码
	private String broadening = "A7"; // 扩展代码
	private String BCC = ""; // 异或校验值

	private String ObuContractVersion = "";// OBU合同版本号，0x00,0x10,0x11,0x12,0x16
	private String VendorType = "";// 厂商类型，当OBU合同版本为0x00或0x10时该字段填写金逸02，聚利03，其它填写00
	private String Offset = "00"; // 写文件偏移量，只有当VendorType为金逸02时，该字段有效，且需要输入偏移量，其它则填写0
	// 18
	private String InfoType = ""; // 信息类型
	private String InfoLen = ""; // 信息长度
	private String InfoData = ""; // 信息内容

	public String command(String version, String type, String offset,
						  String IType, String IData) {
		ObuContractVersion = version;
		VendorType = type;
		this.Offset = EncodingUtil.desToHex(Integer.parseInt(offset), 2);
		InfoType = EncodingUtil.desToHex(Integer.parseInt(IType), 2);// 信息类型
		InfoLen = EncodingUtil.desToHex(IData.length() / 2, 2);// 信息长度
		InfoData = IData;// 信息内容
		// -----------------------------------------------------------------------------
		Length = EncodingUtil.desToHex(
				(broadening + ObuContractVersion + VendorType + Offset
						+ InfoType + InfoLen + InfoData).length() / 2, 4);
		// DATA由代码+扩展子代码+信息类型+信息长度+信息内容按顺序拼接组成
		String DATA = RSCTL + Length + code + broadening + ObuContractVersion
				+ VendorType + Offset + InfoType + InfoLen + InfoData;
		// 异或校验从RSCTL到DATA所有字节的异或值
		BCC = EncodingUtil.yihuo(EncodingUtil.change(DATA));
		// 替换串口帧序列号 DATA 异或值中的制定字符
		String retn = STX + DATA + BCC; // 拼接完整的请求
		return retn;

	}

	public String getSTX() {
		return STX;
	}

	public void setSTX(String sTX) {
		STX = sTX;
	}

	public String getRSCTL() {
		return RSCTL;
	}

	public void setRSCTL(String rSCTL) {
		RSCTL = rSCTL;
	}

	public String getLength() {
		return Length;
	}

	public void setLength(String length) {
		Length = length;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getBroadening() {
		return broadening;
	}

	public void setBroadening(String broadening) {
		this.broadening = broadening;
	}

	public String getBCC() {
		return BCC;
	}

	public void setBCC(String bCC) {
		BCC = bCC;
	}

	public String getInfoType() {
		return InfoType;
	}

	public void setInfoType(String infoType) {
		InfoType = infoType;
	}

	public String getInfoLen() {
		return InfoLen;
	}

	public void setInfoLen(String infoLen) {
		InfoLen = infoLen;
	}

	public String getInfoData() {
		return InfoData;
	}

	public void setInfoData(String infoData) {
		InfoData = infoData;
	}

	public String getObuContractVersion() {
		return ObuContractVersion;
	}

	public void setObuContractVersion(String obuContractVersion) {
		ObuContractVersion = obuContractVersion;
	}

	public String getVendorType() {
		return VendorType;
	}

	public void setVendorType(String vendorType) {
		VendorType = vendorType;
	}

}
